@extends('admin.mainlayout')
@section('title')
    <div class="title"><span>公告管理></span></div>
    <br/>
    <div class="main_top" >
        <form id='search' action="{{urlAdmin('Announce','getIndex')}}" method="get">
            <span>选择时间段</span>
            <input type="text" name="starttime" class="laydate-icon" id="hello2"/><span>到</span>
            <input type="text" name="endtime" class="laydate-icon" id="hello3"/>
            <input type="text" name="keyword" style="width: 120px;height: 21px;margin-left: 100px" placeholder="标题/内容"/>
            <span id="sousuo" >搜索</span>
        </form>
    </div>
    <style type="text/css">
        #sousuo{
            display:inline-block;
            background: #347c1e;
            text-align: center;
            color:white;
            height:25px;
            width:40px;
            margin-left: 40px;
            cursor: pointer;
        }
        #sousuo:hover{
            background-color: #2d94e8;
        }
    </style>
    @endsection
    @section('content')
    <div class="five">
        <div class="header" id="a">发布公告</div>
        <table>
            <tr>
                <th>序号</th>
                <th>标题</th>
                <th>内容</th>
                <th>时间</th>
                <th>详情</th>
                <th>操作</th>
            </tr>
            @if(!empty($res['data']))
                @foreach($res['data'] as $v)
            <tr>
                <td>{{$v['id']}}</td>
                <td>{{$v['title']}}</td>
                @if(strlen($v['content'])>24)
                <td>{{mb_substr($v['content'],0,10)}}...</td>
                @else
                <td>{{$v['content']}}</td>
                @endif
                <td>{{$v['created_at']}}</td>
                <td style="cursor: pointer;" onclick="fn('{{$v['content']}}');">显示详情</td>
                <td style="cursor: pointer;color: red;" onclick="del('{{$v['id']}}');">删除</td>
            </tr>
                @endforeach
            @else
                <tr>
                    <td colspan="6">暂无公告...</td>
                </tr>
            @endif


        </table>
        <div class="del">
            <div class="bot">
                @if($res['prev_page_url'])
                    <p class="prev"><a href="{{$res['prev_page_url']}}">上一页</a></p>
                @endif
                <ul>
                    @foreach($res['pageNoList'] as $v)
                        <li @if($res['current_page'] ==  $v )class="active_list" @endif ><a href="/center/announce?page={{$v}}">{{$v}}</a></li>
                    @endforeach
                </ul>
                @if($res['next_page_url'])
                    <p class="next"><a href="{{$res['next_page_url']}}">下一页</a></p>
                @endif
            </div>
        </div>
    </div>
        <!-- 弹窗 -->
        <div id="fixed" style="display: none">
        <!-- start 发布公告-->
        <form action="{{url('center/announce/add')}}" method="post" id="form1">
        <div class="main">
            <h3>发布公告</h3>

            <div class="one">
                <p>发布对象</p>
                <select name="type">
                    <option value="1">所有人</option>
                </select>
            </div>
            <div class="one">
                <p>标题</p>
                <input name="title" type="text" value=""/>
            </div>
            <div class="two">
                <p>内容</p>
                <textarea name="content"></textarea>
            </div>
            <div class="footer">
                <p id="tijiao">发布</p>
                <p id="quxiao">取消</p>
            </div>
        </div>
            </form>
        <!-- end 发布公告-->
@endsection
            <script>

                //删除公告
                function del(id){

                    layer.confirm('确定要删除该项吗?',{btn:['确定','取消']},function(){

                        layer.closeAll();
                        layer.load(2, {shade: false});
                        $.ajax({
                            type:'post',
                            url:"{{urlAdmin('Announce','postZongAnnounceDel')}}",
                            data:{'id':id,'_token':'{{csrf_token()}}'},
                            dataType:'json',
                            success: function (res) {
                                layer.closeAll();
                                // alert(res);
                                if(res['status']==1){

                                    layer.msg(res.msg,{icon:6});
                                    setTimeout("location.reload()",1500);

                                }else{

                                    layer.msg(res.msg,{icon:5});

                                }

                            }

                        });

                    },function(){

                        layer.msg('已取消了!');

                    });
                }


                function fn(a){

                    layer.open({
                        type: 1,
                        skin: 'layui-layer-rim', //加上边框
                        area: ['420px', '240px'], //宽高
                        content: a
                    });

                }

                window.onload = function(){

                    var Ofabu = document.getElementById('a');


                    Ofabu.onclick = function () {

                        document.getElementById('fixed').style.display = 'block';

                    }

                    document.getElementById('quxiao').onclick = function(){

                        document.getElementById('fixed').style.display = 'none';

                    }

                    document.getElementById('tijiao').onclick = function(){


                        document.getElementById('form1').submit();
                        document.getElementById('fixed').style.display = 'none';
                        //return false;


                    }



                    //时间搜索
                    var oSousuo = document.getElementById('sousuo');
                    var oSearch = document.getElementById('search');

                    oSousuo.onclick = function(){
                        //加载效果
                        layer.load(2, {shade: false});
                        oSearch.submit();

                    }

                    laydate({
                        elem: '#hello2'
                    });
                    laydate({
                        elem: '#hello3'
                    });


                }
            </script>
